<html>
<head><meta charset="utf-8"><title>Shadowing imports · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html">Shadowing imports</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201843967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201843967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201843967">(Jun 24 2020 at 13:03)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> now that <a href="https://github.com/rust-analyzer/rust-analyzer/pull/5015">https://github.com/rust-analyzer/rust-analyzer/pull/5015</a> is going to be merged, should I submit another PR just to remove this comment <a href="https://github.com/rust-analyzer/rust-analyzer/blob/4029628f15c612182ad9da1c652078f9df62f5cf/crates/ra_hir_def/src/item_scope.rs#L54">https://github.com/rust-analyzer/rust-analyzer/blob/4029628f15c612182ad9da1c652078f9df62f5cf/crates/ra_hir_def/src/item_scope.rs#L54</a> or is there more work to do?</p>



<a name="201844123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201844123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201844123">(Jun 24 2020 at 13:04)</a>:</h4>
<p>I think so, though there are other shadowing problems elsewhere: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4716">https://github.com/rust-analyzer/rust-analyzer/pull/4716</a></p>



<a name="201844623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201844623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201844623">(Jun 24 2020 at 13:09)</a>:</h4>
<p>Well, I just got curious and realized my change only fixes depending on the order of imports. So now it's still broken if the glob comes later in the imports</p>



<a name="201844740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201844740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201844740">(Jun 24 2020 at 13:10)</a>:</h4>
<p>e.g., swapping the lines <code>use foo::*; use bar::baz;</code> changes which module is imported</p>



<a name="201844843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201844843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201844843">(Jun 24 2020 at 13:11)</a>:</h4>
<p>yes, that needs some more handling (I actually was surprised that we don't do that already)</p>



<a name="201845754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201845754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201845754">(Jun 24 2020 at 13:20)</a>:</h4>
<p>I think I can solve it in collector by partitioning the imports by glob, then resolving the glob imports first, followed by the non-glob so they can override the glob imports.</p>



<a name="201846983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201846983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201846983">(Jun 24 2020 at 13:32)</a>:</h4>
<p>I don't think that will work, because you can't resolve all glob imports (in the crate) before all named imports. I think the right way to handle it would be to just keep track of whether an import comes from a glob, and allow them to override accordingly</p>



<a name="201847039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201847039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201847039">(Jun 24 2020 at 13:32)</a>:</h4>
<p>In that case let me close <a href="https://github.com/rust-analyzer/rust-analyzer/pull/5033">https://github.com/rust-analyzer/rust-analyzer/pull/5033</a> and I'll work on this some more :)</p>



<a name="201847191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201847191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201847191">(Jun 24 2020 at 13:34)</a>:</h4>
<p>Or rather, let me expand on it</p>



<a name="201852831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201852831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201852831">(Jun 24 2020 at 14:18)</a>:</h4>
<p>here's an example:</p>
<div class="codehilite"><pre><span></span><code><span class="k">mod</span> <span class="nn">a</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">X</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">b</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">a</span>::<span class="n">X</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">c</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">X</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">d</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">c</span>::<span class="n">X</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">b</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>if the glob import gets handled first, when the import in <code>b</code> gets resolved later, the new name in B is 'pushed' through the glob import so it shows up in <code>d</code>, but it shouldn't shadow the already existing <code>X</code> in <code>d</code></p>



<a name="201852917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201852917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201852917">(Jun 24 2020 at 14:19)</a>:</h4>
<p>(that's what's happening <a href="https://github.com/rust-analyzer/rust-analyzer/blob/97c4d06258bace7c9caf211d3a307fff05bdb58e/crates/ra_hir_def/src/nameres/collector.rs#L544-L558">here</a>)</p>



<a name="201919312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201919312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201919312">(Jun 25 2020 at 00:11)</a>:</h4>
<p>ok, I'll use that as a test and try to work on it a bit tonight and tomorrow morning.</p>



<a name="201924389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201924389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201924389">(Jun 25 2020 at 01:44)</a>:</h4>
<p>ok, I just pushed an update. Out of curiosity, I tried doing this:</p>
<div class="codehilite"><pre><span></span><code>pub mod foo {
    pub mod baz {
        pub struct Foo;
    }
}

pub mod bar {
    pub mod baz {
        pub struct Foo;
    }
}

use foo::*;
use bar::*;
use baz::Foo;
</code></pre></div>


<p>mostly because I didn't actually know what to expect from rustc. It turns out rustc considers the <code>baz::Foo</code> to be an error on the <code>baz</code> portion because it's ambiguous. Should I add that kind of tracking in my current PR, or as a follow-up?</p>



<a name="201939090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201939090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201939090">(Jun 25 2020 at 07:27)</a>:</h4>
<p>I'd do it as a follow-up (we don't even have diagnostics for unresolved imports yet, I don't know if we should add them for ambiguous imports)</p>



<a name="201993108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201993108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201993108">(Jun 25 2020 at 16:35)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> I'm working on your comments during my lunch break. I have a solution for the memory usage you brought up that I think works: I extracted the tracking of the <code>ImportType</code> to an <code>FxHashMap&lt;Name, ImportType&gt;</code> that belongs to the <code>DefCollector</code>. The one possible issue I've come across is that there's also tracking being done in <code>ExprCollector</code> in <code>lower.rs</code>. Do I need to ensure the two are somehow connected? Or can they be tracked completely independently?</p>



<a name="201993327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201993327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201993327">(Jun 25 2020 at 16:37)</a>:</h4>
<p>body lowering doesn't do any import resolution yet, I don't think that should be a problem <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="201993465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201993465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201993465">(Jun 25 2020 at 16:38)</a>:</h4>
<p>it can't just be the <code>Name</code> though, can it, since the <code>DefCollector</code> is concerned about the whole crate, right?</p>



<a name="201993487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201993487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201993487">(Jun 25 2020 at 16:38)</a>:</h4>
<p>i.e. you would need <code>(LocalModuleId, Name)</code></p>



<a name="201993607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201993607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201993607">(Jun 25 2020 at 16:39)</a>:</h4>
<p>and actually, maybe you could just make it a set? <code>from_glob_import: FxHashSet&lt;(LocalModuleId, Name)&gt;</code></p>



<a name="201993782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201993782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201993782">(Jun 25 2020 at 16:41)</a>:</h4>
<p>as for the per-namespace thing, I think something like</p>
<div class="codehilite"><pre><span></span><code><span class="k">mod</span> <span class="nn">a</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">b</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">c</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">a</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">b</span>::<span class="n">foo</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>would be a problem if we don't track the globness per namespace</p>



<a name="201996695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/201996695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#201996695">(Jun 25 2020 at 17:07)</a>:</h4>
<p>That's really helpful, thank you. I'll tackle this more after work</p>



<a name="202044327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202044327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202044327">(Jun 26 2020 at 01:33)</a>:</h4>
<p>I'm going to push a broken commit (and amend later) just to get some help on it. For some reason, the macros are never set with your example. Also, in case anyone else needs it (and because it took me an hour to figure out...) here's the lldb invocation I used to get smolstr to show the string value in the watch window: <code>type summary add "&amp;ra_hir_expand::name::Name" -o "value = valobj.GetChildMemberWithName('0').GetChildMemberWithName('0').GetChildMemberWithName('0'); l = value.GetChildMemberWithName('len').GetValueAsUnsigned(0); s = value.GetChildMemberWithName('buf').AddressOf(); return '"%s"'% valobj.process.ReadMemory(s.GetValueAsUnsigned(0),l,lldb.SBError());"</code></p>



<a name="202044508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202044508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202044508">(Jun 26 2020 at 01:36)</a>:</h4>
<p>What I'm seeing in the new test I added, <code>glob_shadowed_per_ns</code>, is that <code>push_res_with_import</code> is never seeing a macro <code>def</code>. I'm not sure why that's the case.</p>



<a name="202065272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202065272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202065272">(Jun 26 2020 at 08:42)</a>:</h4>
<p>hmm macro name resolution is weird, the example is probably wrong. You can achieve the same problem with a <code>struct foo {}</code> and a <code>fn foo() {}</code> though, I think</p>



<a name="202091683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202091683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202091683">(Jun 26 2020 at 13:45)</a>:</h4>
<p>I'm having a hard time figuring out how to validate this with the current test infrastructure. I can see that using the struct would definitely break the old design (track once per all ns), but the testing infrastructure doesn't let me validate where the items come from. Previously I had been using the modules and validating differently named structs within the submodules to validate the right module had been loaded. However, doing that bypasses the test I'm trying to write here.</p>



<a name="202093587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202093587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202093587">(Jun 26 2020 at 13:59)</a>:</h4>
<p>Would an enum work? I'll give that a try</p>



<a name="202093642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202093642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202093642">(Jun 26 2020 at 13:59)</a>:</h4>
<p>yeah, I don't see how you could test this with the current nameres tests, since they just test that there is a name in a certain module, not which one</p>



<a name="202093866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202093866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202093866">(Jun 26 2020 at 14:01)</a>:</h4>
<p>it would be possible to test it e.g. with a type inference test instead (though it would be nicer to test it in the same crate of course, but that would require implementing some new kind of test there)</p>



<a name="202101190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202101190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202101190">(Jun 26 2020 at 14:58)</a>:</h4>
<p>I also had to change the test data a bit. This setup triggers the case:</p>
<div class="codehilite"><pre><span></span><code><span class="k">mod</span> <span class="nn">a</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">foo</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">b</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">c</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">foo</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">d</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">a</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">c</span>::<span class="n">foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">b</span>::<span class="n">foo</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>The previous one was collecting the inline module definitions first and so the check for overlapping globs was never been hit.</p>



<a name="202101263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202101263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202101263">(Jun 26 2020 at 14:59)</a>:</h4>
<p>Where do the type inference tests live btw?</p>



<a name="202101328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202101328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202101328">(Jun 26 2020 at 14:59)</a>:</h4>
<p>The ones in <code>ra_hir_ty</code>?</p>



<a name="202101537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202101537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202101537">(Jun 26 2020 at 15:01)</a>:</h4>
<p>yes</p>



<a name="202101731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202101731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202101731">(Jun 26 2020 at 15:02)</a>:</h4>
<p>the easiest way to test it in type inference would be to make the two <code>foo</code> functions return different types, and then see what type <code>foo()</code> gets</p>



<a name="202102284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202102284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202102284">(Jun 26 2020 at 15:06)</a>:</h4>
<p>Ok good, I was doing just that. I was also adding a field to the structs with the same name but different types and asserting that the field type matches what's expected.</p>



<a name="202102302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202102302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202102302">(Jun 26 2020 at 15:06)</a>:</h4>
<p>Just about to do red/green testing to make sure it actually works <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="202103009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Shadowing%20imports/near/202103009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Shadowing.20imports.html#202103009">(Jun 26 2020 at 15:12)</a>:</h4>
<p>ok, just pushed latest. Should be good for review again. Thanks again for your help <span class="user-mention" data-user-id="129457">@Florian Diebold</span> !</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>